package com.sgcc.sx.pmos.e_sx_home.presenter;

import com.sgcc.sx.pmos.common.base.BasePresenter;
import com.sgcc.sx.pmos.common.http.HttpInterConst;
import com.sgcc.sx.pmos.common.http.HttpRequestUtils;
import com.sgcc.sx.pmos.common.http.MvpNetCallback;
import com.sgcc.sx.pmos.e_sx_home.bean.UserChageSaveBean;
import com.sgcc.sx.pmos.e_sx_home.bean.UserTypeChangeBean;
import com.sgcc.sx.pmos.e_sx_home.contract.UserTypeChangeContract;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;

public class UserTypeChangePresenter extends BasePresenter<UserTypeChangeContract.View> implements UserTypeChangeContract.Presenter {
    /**
     * 获取可转换的身份类型
     * @param tagetMonth
     */
    @Override
    public void getChangeContent(String tagetMonth) {
        Map<String, Object> params = new HashMap<>();
        params.put("tagetMonth", tagetMonth);
        HttpRequestUtils.getInstance().request(params, HttpInterConst.HOME_USERTYPE_CHANGE, new MvpNetCallback<UserTypeChangeBean>(getView(), true) {
            @Override
            public void onError(Call call, Exception e, int id) {
                super.onError(call, e, id);
                // 失败回调 判断界面是否销毁
                if (!isViewAttached()) {
                    return;
                }
                getView().queryChangeContentFaile();
            }

            @Override
            public void onResponse(UserTypeChangeBean response, int id) {
                super.onResponse(response, id);
                if (!isViewAttached()) {
                    return;
                }
                getView().queryChangeContentSuccess(response);
            }
        });
    }


    /**
     * 确认转换身份类型
     * @param startDate
     */
    @Override
    public void ChangeUserType(String startDate,String userType) {
        Map<String, Object> params = new HashMap<>();
        params.put("startDate", startDate);
        params.put("userType", userType);
        HttpRequestUtils.getInstance().request(params, HttpInterConst.HOME_USERTYPE_SAVE_CHANGE, new MvpNetCallback<UserChageSaveBean>(getView(), true) {
            @Override
            public void onError(Call call, Exception e, int id) {
                super.onError(call, e, id);
                // 失败回调 判断界面是否销毁
                if (!isViewAttached()) {
                    return;
                }
                getView().changeUsrTypeFaile();
            }

            @Override
            public void onResponse(UserChageSaveBean response, int id) {
                super.onResponse(response, id);
                if (!isViewAttached()) {
                    return;
                }
                getView().changeUsrTypeSuccess(response);
            }
        });
    }


}
